package Controls
{
	import Objects.GameBitmap;
	
	import Tools.BitmapTool;
	
	import flash.display.BitmapData;

	public class BitmapField extends GameBitmap
	{
		public var filedData:Object;
		public var images:Array;
		public function BitmapField()
		{
			super();
		}
		private var m_text:String;
		public function set text(val:String):void
		{
			if(m_text==val)return;
			m_text=val;
			syncText();
			
		}
		public function get text():String
		{
			return m_text;
		}
		
		protected function syncText():void
		{
			var image:BitmapData=images[0];
			var textImage:BitmapData=new BitmapData(image.width*m_text.length,image.height,true,0);
			var index:int=0;
			while(index<m_text.length)
			{
				var char:String=m_text.charAt(index);
				var charImageIndex:int=filedData[char];
				BitmapTool.draw(textImage,images[charImageIndex],index*image.width,0);
				index++;
			}
			
			setImage(textImage);
		}
		
		public function setup(imageData:Object,columns:int,rows:int,_filedData:Object=null):void
		{
			images=BitmapTool.cut(imageData,columns,rows);
			filedData=_filedData;
		}
	}
}